/*
 *  Copyright (C) 2010 Matthias Buch-Kromann <mbk.isv@cbs.dk>
 * 
 *  This file is part of the IncrementalParser package.
 *  
 *  The IncrementalParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.osdtsystem.incparser.graphs;

import org.osdtsystem.incparser.features.FeatureVector;

/**
 * Nodes are represented by integers. Edges are represented by integers as well,
 * where the lowest bits encode the head on the other end of the node, and
 * the label is encoded in the highest bits.
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public interface Graph extends Cloneable {
    // Local graphs
    int layers();
    int nodes();
    int nodeLayer(int node);
    LocalGraph localGraph(int node, int layer);

    // Features
    int intFeatures();
    int objectFeatures();
    int intFeature(int node, int feature);
    Object objectFeature(int node, int feature);
    void setIntFeature(int node, int feature, int value);
    void setObjectFeature(int node, int feature, Object value);

    // Scores
    int scorers();
    GraphScorer scorer(int scorer);
    float score();
    float localScore(int node);
    float localScore(int node, int scorer);
    float localScoreParent(int node, int scorer);
    float localScoreBase(int node, int scorer);
    float localScoreBest(int node, int scorer);
    void outdateScore(int node, int scorer);
    FeatureVector featureVector();

    // Graph manipulation
    GraphOverlayAddNode makeOverlayAddNode(int layer);
    GraphOverlayAddEdge makeOverlayAddEdge(int layer, int innode, int outnode, int type);
    GraphOverlayRemoveEdge makeOverlayRemoveEdge(int layer, int innode, int outnode, int type);
    GraphOverlayMoveEdge makeOverlayMoveEdge(int layer, int innode, int oldoutnode, int oldtype, int newoutnode, int newtype);
    
    // Cloning and trimming
    void writeToFile(String outputFile);
    void trimToSize();

    // Bit encoding parameters
    int NODEBITS = 22;
    int OTHERBITS = 32 - NODEBITS;
    int FEATUREBITS = OTHERBITS;
    int EDGETYPEBITS = OTHERBITS;
    int SCORERBITS = OTHERBITS;

    // Null feature values
    int[] NULLOBJECTFEATURE = new int[0];
    int NULLINTFEATURE = 0;
}
